package cn.supermarket.controller.service;

import cn.supermarket.common.annotation.Log;
import cn.supermarket.common.core.controller.BaseController;
import cn.supermarket.common.core.entity.Result;
import cn.supermarket.common.core.page.TableDataInfo;
import cn.supermarket.common.enums.BusinessType;
import cn.supermarket.common.utils.SecurityUtils;
import cn.supermarket.system.dto.TSupplierDTO;
import cn.supermarket.system.dto.TWarehouseDTO;
import cn.supermarket.system.entity.TWarehouse;
import cn.supermarket.system.result.TWarehouseResult;
import cn.supermarket.system.service.TWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author yp
 * @Date 2025/3/11:09:07
 */
@RestController
@RequestMapping("/service/warehouse")
public class TWarehouseController extends BaseController {

    @Autowired
    private TWarehouseService tWarehouseService;

    @GetMapping("/list")
    public TableDataInfo list(TWarehouseDTO dto)
    {
        startPage();
        List<TWarehouseResult> list = tWarehouseService.pageList(dto);
        return getDataTable(list);
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('service:warehouse:add')")
    @Log(title = "库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@Validated @RequestBody TWarehouse tWarehouse)
    {
        tWarehouse.setCreateBy(SecurityUtils.getUsername());
        tWarehouse.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(tWarehouseService.save(tWarehouse));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('service:warehouse:edit')")
    @Log(title = "库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@Validated @RequestBody TWarehouse tWarehouse)
    {
        tWarehouse.setUpdateBy(SecurityUtils.getUsername());
        tWarehouse.setUpdateTime(new Date());
        return toAjax(tWarehouseService.updateById(tWarehouse));
    }

    /**
     * 获取列表选择框
     */
    @GetMapping("/optionSelect")
    public Result optionSelect()
    {
        List<TWarehouseResult> posts = tWarehouseService.optionSelect();
        return success(posts);
    }

    /**
     * 详细信息
     */
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable String id)
    {
        return success(tWarehouseService.getById(id));
    }
}
